/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Game;


import chatroom.ClientGame;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author Caca
 */
public class Square extends JLabel{
    private int col;
    private int row;

    private String isState;
    private ClientGame clientGame;
    private boolean onGame;
   

    public String getIsState() {
        return isState;
    }

    public void setIsState(String isState) {
        this.isState = isState;
    }
   

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    

    public Square(int col, int row, String isState,ClientGame cg) {
        this.col = col;
        this.row = row; 
        this.isState = isState;
        this.clientGame = cg;
        loadIcon("");
        
        
           this.addMouseListener(new MouseListener() {

                @Override
                public void mouseClicked(MouseEvent e) {               
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    loadIcon(getIsState());
                    clientGame.appendStatus("Move: " + getRow() + "," + getCol());
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    
                }
            });
    }  
    
    public void setSquare(int col, int row, String isState)
    {
        this.col = col;
        this.row = row;
        this.isState = isState;
    }
    
    public void loadIcon(String myState)
    {
         String urlImage;
        if(myState =="X"){
           urlImage ="/Game/CellX.png";
           URL urlToImage = this.getClass().getResource(urlImage);
           ImageIcon icon = new ImageIcon(urlToImage);  
           setIcon(icon);
        } else  if(myState =="O"){
           urlImage ="/Game/CellO.png";
           URL urlToImage = this.getClass().getResource(urlImage);
           ImageIcon icon = new ImageIcon(urlToImage);  
           setIcon(icon);
        } else  if(myState ==""){
           urlImage ="/Game/CellNULL.png";
           URL urlToImage = this.getClass().getResource(urlImage);
           ImageIcon icon = new ImageIcon(urlToImage);  
           setIcon(icon);
        }
         
    }
   
    
    
    
    
}
